from django.shortcuts import render

# Create your views here.
from django.shortcuts import render

# Create your views here.
from rest_framework import generics
from rest_framework import permissions
from .models import NeedAuthenticatedSchoolMateProfile
from .serializers import NeedAuthenticatedSchoolMateProfileSerializer
from schoolmate.permissions import IsOwnerOrSuperUser, ProfileUnique


class NeedAuthenticatedSchoolMateProfileListView(generics.CreateAPIView):
    """
    post:
    创建校友身份待验证文档，需要携带token，token存放在header中的Authorization字段中值为Bearer <token>    """
    queryset = NeedAuthenticatedSchoolMateProfile.objects.all()
    serializer_class = NeedAuthenticatedSchoolMateProfileSerializer
    permission_classes = (IsOwnerOrSuperUser, ProfileUnique, permissions.IsAuthenticated)

    # 将request.user与author绑定
    def perform_create(self, serializer):
        serializer.save(user=self.request.user)


class NeedAuthenticatedSchoolMateProfileDetailView(generics.RetrieveDestroyAPIView):
    """
    get:
    查看校友身份待验证文档，需要携带token，token存放在header中的Authorization字段中值为Bearer <token>

    delete:
    删除校友身份待验证文档，需要携带token，token存放在header中的Authorization字段中值为Bearer <token>
    """
    queryset = NeedAuthenticatedSchoolMateProfile.objects.all()
    serializer_class = NeedAuthenticatedSchoolMateProfileSerializer
    permission_classes = (IsOwnerOrSuperUser,)  # 登陆才能查看

    # def perform_create


from rest_framework_simplejwt.views import TokenObtainPairView
from rest_framework.permissions import AllowAny
from .serializers import MyTokenObtainPairSerializer


class MyObtainTokenPairView(TokenObtainPairView):
    """
    post:
    登陆，
    return: 123321123
    """
    permission_classes = (AllowAny,)  # 每个人都可以登陆
    serializer_class = MyTokenObtainPairSerializer



